package org.jeecg.modules.logistics.dictionaries.qz_dic.service.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.modules.logistics.dictionaries.qz_dic.entity.QzDicInfo;
import org.jeecg.modules.logistics.dictionaries.qz_dic.mapper.QzDicMapper;
import org.jeecg.modules.logistics.dictionaries.qz_dic.service.IQzDicService;
import org.jeecg.modules.logistics.manage.hw_info.entity.HwInfo;
import org.jeecg.modules.logistics.manage.hw_info.mapper.HwInfoMapper;
import org.jeecg.modules.logistics.manage.hw_info.service.IHwInfoService;
import org.jeecg.modules.logistics.table.qzfl.entity.Qzfl;
import org.jeecg.modules.logistics.table.qzlx.entity.Qzlx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2019/12/24  10:55
 */
//TODO qzfl           求助分类
//TODO qzlx           求助类型
@Service
@DS("freight")
public class QzDicServiceImpl implements IQzDicService {
    @Autowired
    QzDicMapper qzDicMapper;

    @Override
    public QzDicInfo getQzDicInfo() {
        QzDicInfo qzDicInfo = new QzDicInfo();
        qzDicInfo.setQzflList(qzDicMapper.getAllQzfl());
        qzDicInfo.setQzlxList(qzDicMapper.getAllQzlx());
        return qzDicInfo;
    }

    @Override
    public int putQzDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "qzfl":
                Qzfl qzfl = (Qzfl) jsonObj.get("data");
                return qzDicMapper.PutQzfl(qzfl);
            case "qzlx":
                Qzlx qzlx = (Qzlx) jsonObj.get("data");
                return qzDicMapper.PutQzlx(qzlx);
            default:
                return 0;
        }
    }

    @Override
    public int delQzDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        int id = jsonObj.getInt("data");
        switch (dic) {
            case "qzfl":
                return qzDicMapper.DelQzfl(id);
            case "qzlx":
                return qzDicMapper.DelQzlx(id);
            default:
                return 0;
        }
    }

    @Override
    public int addQzDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "qzfl":
                Qzfl qzfl = (Qzfl) jsonObj.get("data");
                return qzDicMapper.AddQzfl(qzfl);
            case "qzlx":
                Qzlx qzlx = (Qzlx) jsonObj.get("data");
                return qzDicMapper.AddQzlx(qzlx);
            default:
                return 0;
        }
    }
}
